
import sys, json
import pymongo

file = open('sq169.text_event.log')
client = pymongo.MongoClient('sq169.houston.hp.com')

for line in file.readlines():
    if line.startswith('{"Message"'):
        rkey = json.loads(line.strip())['Message']
        rkeys = rkey.split('.')
        dbname = rkeys[0]
        msg_name = '%s_%s' % (rkeys[1], rkeys[-1])
        print msg_name
    elif line.startswith('<header>'):
        continue
    elif line.startswith('{'):
        d = json.loads(line.strip())
        db = client[dbname]
        db[msg_name].insert(d)
